#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/*
 * ./led_test /dev/imx6_led on
 * ./led_test /dev/imx6_led off
 */

int main(int argc,char **argv)
{
	int fd;
	char status;

	/* 判断输入参数 */
	if (argc != 3) 
	{
		printf("input error\n");
		return -1;
	}

	fd = open(argv[1],O_RDWR);
	if(fd < 0){
		printf("can not open file %s\n", argv[1]);
		return -1;

	}

	/* strcmp (string compare)字符串比较函数，根据比较结果放回整数
	 * strcmp(str1,str2)
	 * str1=str2，则返回零；若str1<str2，则返回负数；若str1>str2，则返回正数
	 */

	if (0 == strcmp(argv[2], "on"))   
	{
		status = 1;
		write(fd, &status, 1);
	}
	else
	{
		status = 0;
		write(fd, &status, 1);
	}
	
	close(fd);

	
	return 0;
}

